﻿package util.select {
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.*;
	
	public class SelectItem extends Sprite {
		private var label:String;
		private var value:String;
		
		private var tf:TextField;
		private var editor:Editor;
		private var align:String;
		private var type:String;
		
		public function SelectItem(label:String, value:String, align:String, type:String, editor:Editor):void {
			this.label = label;
			this.value = value;
			this.editor = editor;
			this.align = align;
			this.type = type;
			initView();
			addEventListener(MouseEvent.MOUSE_OVER, onOverHandler);
			addEventListener(MouseEvent.MOUSE_OUT, onOutHandler);
			addEventListener(MouseEvent.CLICK, onClickHandler);
		}
		
		private function initView():void {
			tf = getChildByName("txt") as TextField;
			tf.text = label;
			tf.width = tf.textWidth + 8;
			tf.background = true;
			tf.backgroundColor = 0xFFFFFF;
			tf.border = true;
			tf.borderColor = 0x339966;
			var format:TextFormat = tf.getTextFormat(0, 1);
			format.align = align;
			tf.setTextFormat(format, 0, tf.text.length);
		}
		
		private function onOverHandler(event:MouseEvent):void {
			tf.backgroundColor = 0x99CCFF;
		}
		private function onOutHandler(event:MouseEvent):void {
			tf.backgroundColor = 0xFFFFFF;
		}
		private function onClickHandler(event:MouseEvent):void {
			if (type == "size") {
				editor.hideSizeList(int(value));	
			}
			else {
				editor.hideFamilyList(value);
			}
		}
		
		public function setWidth(width:int):void {
			tf.width = width;
		}
	}
}